package com.bana.fvs.app.main.adapter;

import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bana.fvs.R;
import com.bana.fvs.app.common.ConstantsField;
import com.bana.fvs.app.main.entity.FogControllerItem;
import com.bana.fvs.app.main.entity.FogZoneListItemBean;
import com.wei.commonlibrary.utils.GlobalContext;

import java.util.List;

public class FogControllerAdapter extends RecyclerView.Adapter<FogControllerAdapter.ViewHolder> {
    public List<FogControllerItem> datas;
    private onItemClickListener mOnItemClickListener;


    public FogControllerAdapter(List<FogControllerItem> datas) {
        this.datas = datas;
    }

    public interface onItemClickListener {
        void onClickListener(int position);
    }

    public void setOnItemClickListener(onItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_layout_fog_controller_list, viewGroup, false);
        return new ViewHolder(view);
    }

    private static final String TAG = "debug_MyAdapter";

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        FogControllerItem bean = datas.get(position);
        if (null == bean) return;

        holder.tvControllerName.setText(bean.getKzqmc());

        holder.tvWdzt.setText(bean.getWdkzsm());
        if(bean.getSbzt()==1){
            holder.ivSbzt.setImageResource(R.drawable.equipment_normal);
        }else{
            holder.ivSbzt.setImageResource(R.drawable.equipment_error);
        }

        holder.ll_rv_container.setOnClickListener(v -> {
            if (null != mOnItemClickListener) {
                mOnItemClickListener.onClickListener(position);
            }
        });
    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return datas.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        //标题
        public TextView tvControllerName;
        //可见度
        public TextView tvWdzt;

        public ImageView ivSbzt;

        public LinearLayout ll_rv_container;

        public ViewHolder(View view) {
            super(view);
            tvControllerName = (TextView) view.findViewById(R.id.tvControllerName);
            tvWdzt = (TextView) view.findViewById(R.id.tvWdzt);
            ivSbzt=(ImageView) view.findViewById(R.id.ivSbzt);
            ll_rv_container = (LinearLayout) view.findViewById(R.id.ll_rv_container);
        }
    }
}
